package com.test.controller;


import com.test.dao.InfoDao;
import com.test.entity.InfoDto;
import com.test.entity.StuAllInfoDto;
import com.test.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/info")
public class InfoController {
    @Autowired
    private InfoService infoService;


    @RequestMapping("/submitReleaseInfo")
    @ResponseBody
    public String submitReleaseInfo(HttpSession session, InfoDto infoDto){
        String acount  = session.getAttribute("comp_acount").toString();
        List<InfoDto> checkinfoDto = infoService.selectReleaseInfo(acount);
        int result = 0;
        int num = 0;
        if(checkinfoDto.size()>0){
            for(int i=0;i<checkinfoDto.size();i++){
                if(checkinfoDto.get(i).getRecruit_material().equals(infoDto.getRecruit_material())
                        &&checkinfoDto.get(i).getRecruit_job().equals(infoDto.getRecruit_job())
                        &&checkinfoDto.get(i).getRecruit_address().equals(infoDto.getRecruit_address())
                        &&checkinfoDto.get(i).getRecruit_time().equals(infoDto.getRecruit_time())
                        &&checkinfoDto.get(i).getRecruit_name().equals(infoDto.getRecruit_name())
                        &&checkinfoDto.get(i).getU_acount().equals(acount)
                ){
                    num++;
                }
            }
            if(num==0){
                infoDto.setU_acount(acount);
                result = infoService.insertReleaseInfo(infoDto);
            }
        }else{
            infoDto.setU_acount(acount);
            result = infoService.insertReleaseInfo(infoDto);
        }
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }

    @RequestMapping("/TeasubmitReleaseInfo")
    @ResponseBody
    public String TeasubmitReleaseInfo(HttpSession session, InfoDto infoDto){
        String acount  = session.getAttribute("tea_u_acount").toString();
        List<InfoDto> checkinfoDto = infoService.selectReleaseInfo(acount);
        int result = 0;
        int num = 0;
        if(checkinfoDto.size()>0){
            for(int i=0;i<checkinfoDto.size();i++){
                if(checkinfoDto.get(i).getRecruit_material().equals(infoDto.getRecruit_material())
                        &&checkinfoDto.get(i).getRecruit_job().equals(infoDto.getRecruit_job())
                        &&checkinfoDto.get(i).getRecruit_address().equals(infoDto.getRecruit_address())
                        &&checkinfoDto.get(i).getRecruit_time().equals(infoDto.getRecruit_time())
                        &&checkinfoDto.get(i).getRecruit_name().equals(infoDto.getRecruit_name())
                        &&checkinfoDto.get(i).getU_acount().equals(acount)
                ){
                    num++;
                }
            }
            if(num==0){
                infoDto.setU_acount(acount);
                result = infoService.insertReleaseInfo(infoDto);
            }
        }else{
            infoDto.setU_acount(acount);
            result = infoService.insertReleaseInfo(infoDto);
        }
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }

    @RequestMapping("/AppsubmitReleaseInfo")
    @ResponseBody
    public String AppsubmitReleaseInfo(HttpSession session, InfoDto infoDto){
        String acount = null;
        if(infoDto.getU_acount()!=null&&!"".equals(infoDto.getU_acount())){
             acount  = infoDto.getU_acount();
        }else{
            acount  = "renxinbo";
        }
        List<InfoDto> checkinfoDto = infoService.selectReleaseInfo(acount);
        int result = 0;
        int num = 0;
        if(checkinfoDto.size()>0){
            for(int i=0;i<checkinfoDto.size();i++){
                if(checkinfoDto.get(i).getRecruit_material().equals(infoDto.getRecruit_material())
                        &&checkinfoDto.get(i).getRecruit_job().equals(infoDto.getRecruit_job())
                        &&checkinfoDto.get(i).getRecruit_address().equals(infoDto.getRecruit_address())
                        &&checkinfoDto.get(i).getRecruit_time().equals(infoDto.getRecruit_time())
                        &&checkinfoDto.get(i).getRecruit_name().equals(infoDto.getRecruit_name())
                        &&checkinfoDto.get(i).getU_acount().equals(acount)
                ){
                    num++;
                }
            }
            if(num==0){
                infoDto.setU_acount(acount);
                result = infoService.insertReleaseInfo(infoDto);
            }
        }else{
            infoDto.setU_acount(acount);
            result = infoService.insertReleaseInfo(infoDto);
        }
        if(result>0){
            return "已保存";
        }else{
            return "未保存";
        }
    }


}
